<%@ page import="com.work.bean.Work" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/10/6
  Time: 15:37
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>历史作业</title>
</head>
<%@include file="teacher_common.jsp" %>
<script>
    $(function () {
        $("#history_work_li").attr('class', 'active');
    });
</script>
<style>
    th, td {
        width: 160px;
        padding: 10px;
        background-color: rgb(180, 193, 224);
    }
</style>

<%
    List<Work> works = (List<Work>) session.getAttribute("works");

    int pageNumber = (Integer) session.getAttribute("pageNumber");
    int whichPage = (Integer) session.getAttribute("whichPage");
    int countPage = (Integer) session.getAttribute("countPage");
    boolean flag = false;
    if (session.getAttribute("flag") != null) {
        flag = (Boolean) session.getAttribute("flag");
    }
//
//    String menuCategory = "";
//
//    if (session.getAttribute("typeName") != null) {
//        menuCategory = (String) session.getAttribute("typeName");
//    }

    if (session.getAttribute("error") != null) {
        out.print(session.getAttribute("error"));
    }
%>
<body>

<div>
    <div>
        <div style="margin-left: 250px">
            <h3 style="margin-top: 50px">作业列表</h3>
            <center><table border="1px" cellspacing="0px" cellpadding="20px" style="margin-left: 10px">
                <thead>
                <tr>
                    <th>开始时间</th>
                    <th>截止时间</th>
                    <th>文件名称</th>
                    <th>操作</th>
                    <th>完成进度</th>

                </tr>
                </thead>
                <tbody>

                <%
                    if (works != null) {
                        for (Work work : works) {%>

                <tr>
                    <td><%=work.getStartTime()%>
                    </td>
                    <td><%=work.getEndTime()%>
                    </td>
                    <td><%=work.getWorkName()%>
                        <br>
                        <a href="${pageContext.request.contextPath}/readonline.jsp?readOnlinePath=<%=work.getReadOnLinePath()%>">预览</a>
                        <br>
                        <a href="${pageContext.request.contextPath}/download?path=<%=work.getDownloadPath()%>">下载</a>

                    </td>

                    <td>

                        <%

                            if (work.getDistribute() == 0) {%>

                        <a href="${pageContext.request.contextPath}/my_class?workID=<%=work.getId()%>">分配</a>
                        <%
                            }
                        %>
                        <br>
                        <%--<a href="${pageContext.request.contextPath}/my_student?workID=<%=work.getId()%>">分配到学生</a>--%>
                        <br> <a href="#" onclick="deleteById(<%=work.getId()%>)">删除</a></td>

                    <td>
                        <%

                            if (work.getDistribute() == 0) {%>

                        未分配
                        <%
                        } else {%>

                        <a href="${pageContext.request.contextPath}/finish?workId=<%=work.getId()%>&isFinish=1"><%=work.getFinishProcess()%>
                        </a>
                        <%
                            }
                        %>
                    </td>
                </tr>

                <%
                    }
                } else {
                %>

                <tr>
                    <td colspan="5">暂无数据</td>
                </tr>
                <%
                    }
                %>

                <tr>
                    <td colspan="5" align="center">
                        <button onclick="jump('first')">最前页</button>
                        <button onclick="jump('last')">上一页</button>
                        <button onclick="jump('next')">下一页</button>
                        <button onclick="jump('final')">最后页</button>
                        跳转到第<select id="whichPage" onchange="jumpChange(0,this[selectedIndex].value)">
                        <%
                            if (pageNumber != 0) {

                                for (int i = 0; i < pageNumber; i++) {

                                    if ((i + 1) == whichPage) {
                        %>
                        <option selected="selected"><%=i + 1%>
                        </option>
                        <%
                        } else {%>
                        <option><%=i + 1%>
                        </option>
                        <%
                                    }
                                }

                            }
                        %>

                    </select>页
                        每页显示
                        <select id="pageCount" onchange="jumpChange(1,this[selectedIndex].value)">

                            <option><%=countPage%>
                            </option>
                            <%

                                for (int i = 3; i <= 15; i += 3) {
                                    if (i == countPage) {%>

                            <option selected="selected"><%=countPage%>
                            </option>
                            <%} else {%>
                            <option><%=i%>
                            </option>
                            <%
                                    }

                                }
                            %>
                        </select>条

                    </td>
                </tr>

                </tbody>
            </table>
            </center>
        </div>
    </div>
</div>

</body>

<script type="text/javascript">

    <%--function getFinish(id) {--%>

    <%--alert(id);--%>

    <%--$.ajax("${pageContext.request.contextPath}/finish?workId=" + id, function (data) {--%>

    <%--alert(data);--%>
    <%--$("#finish").html(data);--%>
    <%--});--%>

    <%--}--%>

    function deleteById(id) {

        if (confirm("确认删除？")) {

            window.location = "/history_work?deleteId=" + id;
            alert("删除成功");
        }
    }

    function jump(type) {

        var objW = document.getElementById("whichPage"); //定位id
        var indexW = objW.selectedIndex; // 选中索引
        var whichPage = objW.options[indexW].text; // 选中文本

        var objP = document.getElementById("pageCount"); //定位id
        var indexP = objP.selectedIndex; // 选中索引
        var pageCount = objP.options[indexP].text; // 选中文本

        if (type == 'first') {

            if (whichPage == 1) {

                alert("当前已是第一页");

            } else {

                window.location = "/history_work?countPage=" + pageCount + "&whichPage=1";
            }

        } else if (type == 'last') {

            if (whichPage == 1) {
                alert("当前已是第一页");
            } else {

                window.location = "/history_work?countPage=" + pageCount + "&whichPage=" + (whichPage - 1);
            }

        } else if (type == 'next') {

            if (whichPage == <%=pageNumber%>) {

                alert("当前已是最后页");

            } else {

                window.location = "/history_work?countPage=" + pageCount + "&whichPage=" + (whichPage - (-1));
            }

        } else if (type == 'final') {

            if (whichPage == <%=pageNumber%>) {
                alert("当前已是最后页");
            } else {

                window.location = "/history_work?countPage=" + pageCount + "&whichPage=<%=pageNumber%>";
            }
        }

    }

    function jumpChange(type, value) {

        if (type == 0) {

            var objP = document.getElementById("pageCount"); //定位id
            var indexP = objP.selectedIndex; // 选中索引
            var pageCount = objP.options[indexP].text; // 选中文本

            window.location = "/history_work?countPage=" + pageCount + "&whichPage=" + value;

        } else if (type == 1) {

            var objW = document.getElementById("whichPage"); //定位id
            var indexW = objW.selectedIndex; // 选中索引
            var whichPage = objW.options[indexW].text; // 选中文本

            window.location = "/history_work?countPage=" + value + "&whichPage=1";

        }
    }

    function add() {

        window.location = "teacher_add_work.jsp";

    }


</script>
</html>
